package com.org.cys.util;

import java.security.MessageDigest;
import com.org.cys.pojo.base.Const;

/**
 * MD5加密工具类
 * @author caiyushen
 * */
public class MD5{

	/**
	 * MD5加密方式
	 * */
	public static String md5(String str) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(str.getBytes());
			byte b[] = md.digest();

			int i;

			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			str = buf.toString();
		} catch (Exception e) {
			e.printStackTrace();

		}
		return str;
	}
	
	/**
	 * 用户密码加密
	 * @param userAccount 用户账号
	 * @param userPassword 用户密码
	 * @author caiyushen
	 * */
	public static String convertPassword(String userAccount,String userPassword){
		//加密串
		String result = md5(userPassword+Const.passwordKey+userAccount);
		return result;
	}
	
	
	public static void main(String[] args) {
		System.out.println(convertPassword("admin","123456"));
	}

}
